#!/bin/bash
TERMUX_DIR="$PREFIX"
INSTALL_SHELL="$TERMUX_DIR/Install.sh"
URL="https://gitee.com/HornLeaf/proot-arch/raw/master"

trap '' 2

if [[ ! $HOME == "/data/data/com.termux/files/home" ]];then
echo '当前脚本仅支持 Termux' && exit
fi

echo 'Powered By TRSS MTArch'

if [[ $TERMUX_DIR == /data/data/com.termux/files/usr ]];then
    if [ ! -f $HOME/.termux/font.ttf ];then
        echo "正下载字体..."
       curl -OL $URL/font.ttf &&
        if ! mv font.ttf $HOME/.termux/;then
            echo '布局释放失败'
            exit
        else
            termux-reload-settings
            echo "释放完成"
        fi
    fi
fi

    echo "正下载构建包..."
    curl -OL $URL/proot-tool.tar.xz &&
        if ! tar --remove-files -Jxvf proot-tool.tar.xz -C $TERMUX_DIR;then
            echo '构建包释放失败'
            exit
        else
            echo "释放完成"
        fi
if [[ -f $TERMUX_DIR/bin/proot && -f $TERMUX_DIR/bin/proot-tool && -f $TERMUX_DIR/bin/minitar ]];then
    chmod 755 $(command -v proot-tool proot minitar repo)
else
    echo '异常'
    exit
fi

exec bash "$INSTALL_SHELL" "$@"
exit